<?php
include_once("codelibrary/inc/variables.php");
include_once("session.php");
include_once("codelibrary/inc/functions.php");
$page="pay-type-view-details.php";
$business_id = $_SESSION['business_id'];

		if(isset($_REQUEST['Submit']))
		{
		    $num = $_POST['totalNoOfRecords'];
			
			for($j=1;$j<=$num;$j++)
			{
			    $sort_order = "TR_Order".$j;
				$sortorder = $$sort_order;
				
				$paytypeid = "paytypeid".$j;
				$paytype_id1 = $$paytypeid;
				
				mysql_query("update $pay_type_table set sortorder='".$sortorder."' where paytype_id='".$paytype_id1."'");
			}
		}
		if(!isset($pageno))
		$pageno=0;
	
		if(!isset($sortField))
		{
			$sortField="sortorder";
		}
		
		if(!isset($order))
		{
				//variable on the basis of which sorting will be performed
				$order="asc";
		}

		//index of table from where to show the records
			$startIndex=$paging*($pageno);
		
		//limit variable 
			$limit=" LIMIT $startIndex,$paging";
			
		    $adminQuery = "select * from $pay_type_table where business_id='$business_id'";
	 
?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="LTR" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Online Appointment</title>
<script>
            
			var iDelTotalChecked=0
			function objDelChecked(chk)
			{
				if(chk.checked==true)
					iDelTotalChecked=iDelTotalChecked+1
				else
					iDelTotalChecked=iDelTotalChecked-1
			}

			function ConfirmChoice() 
			{ 
				if(iDelTotalChecked==0)
				{
					alert("Please select at least one record to delete.");
					return false; 
				}
				else
				{
					answer = confirm("Are you sure you want to Delete the selected Payment Type(s)?")

					if (answer !=0) 
					{ 
						return true; 
					} 
					else
					{
						return false; 
					}
				}
			}

			function goDelete()
			{		
				document.frm2.action="delete-pay-type.php";
				document.frm2.submit();
			}

			function goEdit(idval)
			{
			    
				document.frm2.id.value=idval;
				document.frm2.action="edit-pay-type.php";
				document.frm2.submit();
			}

			function send(pn,ord,sf,srchkwd)
			{	
				document.frm2.pageno.value=pn;
				document.frm2.order.value=ord;
				document.frm2.sortField.value=sf;
				document.frm2.keyword.value=srchkwd;
				document.frm2.submit();
			}
</script>
<script language="JavaScript1.2" src="codelibrary/js/common.Js"></script>


<base >
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>Staff Management</title>

</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">


<table cellpadding="0" cellspacing="0" border="0"><tr>
  <td style="background:url(images/top.gif) repeat-x top; ">
<table cellpadding="0" cellspacing="0" border="0" style="width:764px" align="center"> 
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" border="0" style="height:57">
				<tr>
					<td height="57">
<? html_header(); ?>					</td>
				</tr>
			</table>


		</td>
	</tr>
	<tr>
		<td>





<table border="0" width="105%" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="col_left">

<table border="0"cellspacing="0" cellpadding="0" class="box_width_left">
	<tr><td width="100%">
		<table border="0" cellspacing="0" cellpadding="0">
<tr><td>

<table border="0" width="100%" cellspacing="0" cellpadding="0" class="">
  <tr>
    <td>
    <table border="0" width="100%" cellspacing="0" cellpadding="0"  class="" height="91">
  <tr>
    <td align="center" height="91">
    <img border="0" src="images/logo.jpg" width="208" height="86"></td>
  </tr>
</table>
</td>
  </tr>
</table>
</td></tr>


          <tr>
            <td>
<table border="0" width="100%" cellspacing="0" cellpadding="0"  class="box_header_txt" height="48">
  <tr>
    <td style="background-image: url(images/1_bg2-2.gif)" height="1">
      <p style="margin-top: 16"> </td>
  </tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0"   style="border-bottom:12px solid #ffffff;">
  <tr>
    <td>
    <table border="0" width="100%" cellspacing="0" cellpadding="0"  style="margin-bottom:0px;background:#7C7C7C url(images/1_line.gif) no-repeat left bottom;" >
  <tr>
    <td  style="padding:3px 16px 8px 25px;">
      <? include("link1.php");?>
    </td>
  </tr>
</table>
</td>
  </tr>
</table>
            </td>
          </tr>


          <tr>
            <td class="">&nbsp;
</td>
          </tr>

		</table>
	</td>
	<td><img src="images/spacer.gif" border="0" alt="" width="15" height="1"></td></tr>
</table>

    </td>

    <td width="100%" valign="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0"  class="cont_header_txt">
  <tr>
    <td>
			<table border="0" cellpadding="0" cellspacing="0" bgcolor="#EAEAEA" class="cont_header_txt">
				<tr>
					<td><img src="images/1_q1.gif" border="0" alt="" width="45" height="39"></td>
					<td style="width:100%">Create Personnel Record</td>
					<td><img src="images/1_q2.gif" border="0" alt="" width="10" height="39"></td>
				</tr>
			</table>										 
			</td>
  </tr>
</table>


						
						<table cellpadding="0" cellspacing="0" border="0" style="border:0px solid #DEDEDE; border-width:0px 1px 0px 1px;">
                          <tr>
                            <td style="background:#ffffff;border:0px solid #ffffff; border-width:18px 5px 10px 5px;"><!-- new_products //-->
                                <table border="0" width="" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td><?php
		if((isset($sortField)&& $sortField!="") && (isset($order) && $order!=""))
			{
				$sortcriteria=$sortField;
				$sortordering=$order;
			}
			else
			{
				$sortcriteria="sortorder";
			    $sortordering="asc";
            }
	
			
		$adminQuery.=" ORDER BY $sortcriteria $sortordering";
		//echo $adminQuery;
		$adminRecord=mysql_query($adminQuery);
	    $totalNoOfRecords=mysql_num_rows($adminRecord);
	    $pagesReq=ceil($totalNoOfRecords/$paging);
		
		?>
                  <form name="frm2" method="post" action="<?=$page;?>">
                    <input type="hidden" name="pageno" value="<?=$pageno;?>" >
                    <input type="hidden" name="limit" value="<?=$paging;?>" >
                    <input type="hidden" name="totalNoOfRecords" value="<?=$totalNoOfRecords;?>" >
                    <input type="hidden" name="order" value="<?=$order;?>">
                    <input type="hidden" name="sortField" value="<?=$sortField;?>">
                    <input type="hidden" name="search" value="<?=$search;?>">
                    <input type="hidden" name="keyword" value="<?=$keyword;?>">
                    <input type="hidden" name="activate_status" value="<? if(isset($activate_status)) echo $activate_status;?>">
					<input type="hidden" name="id" >
                    <table cellpadding="0" cellspacing="0" border="0" style="border:0px solid #DEDEDE; border-width:0px 1px 0px 1px;">
                      <tr>
                        <td style="background:#ffffff;border:0px solid #ffffff; border-width:18px 5px 10px 5px;"><table border="0" width="" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                                  <tr>
                                    <td><table width="100%" border="0" cellpadding="3" cellspacing="2">
                                        <tr>
                                          <!-- error info starts-->
                                          <td align="center" class="errTxt"><? 
						if(isset($msg))
						{?>
                                            Payment Type
                                            <?=$msg;?>
                                            Successfully.
                                            <? 
						}
						?>
                                            &nbsp;</td>
                                          <!-- error info ends-->
                                        </tr>
                                        <tr>
                                          <!-- error info starts-->
                                          <td align="center" class="errTxt">&nbsp;</td>
                                          <!-- error info ends-->
                                        </tr>
                                        <tr>
                                          <td valign="top"><!-----------------Content Table starts here------------------->
                                            <?
	                            ##############outer if starts###########################
	 
	  
      
	  if($totalNoOfRecords>0) 
				{ 
	?>
                                            <table width="100%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#FFDBCA" class="table" background-color ="#ffffff">
                                              <tr align="left">
                                                <td width="8%" class="thead" align="center"><input name="delete" type="submit" class="button" value="Delete" onClick="if(ConfirmChoice())goDelete();else return false;" align="center">
                                                </td>
                                                <td class="thead" nowrap width="14%" align="center"><a href="javascript:;" onClick="send(<? print $pageno;
													print ",'";
													print "asc";
													print "'";
													print ",";

													print "'";
													print "description";
													print "',";
													print "'";
													print trim($keyword);
													print "'";
													?>); return false;"> <img src="images/up.gif" alt="Up" width="11" height="5" border="0"></a><span class="simpletxt">Description</span><a href="javascript:;"onClick="send(<? print 				 $pageno;
													print ",'";
													print "desc";
													print "'";
													print ",";
													print "'";
													print "description";
													print "',";
													print "'";
													print trim($keyword);
													print "'";
													?>); return false;"><img src="images/down.gif" alt="Down" width="11" height="5" border="0"></a> </td>
                                                
                                                <td class="thead" nowrap width="14%" align="center"><a href="javascript:;" onClick="send(<? print $pageno;
													print ",'";
													print "asc";
													print "'";
													print ",";
													print "'";
													print "sortorder";
													print "',";
													print "'";
													print trim($keyword);
													print "'";
													?>); return false;"> <img src="images/up.gif" alt="Up" width="11" height="5" border="0"></a><span class="simpletxt">Sort Order</span><a href="javascript:;"onClick="send(<? print 				 $pageno;
													print ",'";
													print "desc";
													print "'";
													print ",";
													print "'";
													print "sortorder";
													print "',";
													print "'";
													print trim($keyword);
													print "'";
													?>); return false;"><img src="images/down.gif" alt="Down" width="11" height="5" border="0"></a> </td>
                                                <td class="simpletxt" width="17%" align="center"> Action </td>
                                              </tr>
                                              <?
							#################while to print content row start########
							$adminQuery.=$limit;
	  						//echo $adminQuery; 
							$Record=mysql_query($adminQuery);	
							$i=1;
			                while($fetchRow=mysql_fetch_array($Record))
							{
				               $id=$fetchRow['paytype_id'];
							   $sortorder=$fetchRow['sortorder'];
						?>
                                              <tr align="left">
                                                <td height="23" class="smallText" align="center"><input name="checkbox[]" type="checkbox" value="<?=$fetchRow['paytype_id'];?>" onClick='objDelChecked(this)' >
                                                </td>
                                                <td class="smallText" align="center"><?
					   echo $fetchRow['description'];
					   
					  ?>
                                                </td>
                                                
                                                <td class="smallText" align="center"><input type="text" name="<?='TR_Order'.$i;?>" value="<?=$sortorder;?>" size="12">
                                                </td>
                                                <td class="smallText" noWrap align="center"><a href="javaScript:;" onClick="goEdit('<?=$fetchRow["paytype_id"]?>');return false;" class="alink">Edit</a> 
                                                  <input type="hidden" name="<?='paytypeid'.$i;?>" value="<?=$id;?>">
                                                  <? 
												$i++;
										  }  ##############end of while###########
								?>
                                            </table>
                                            <? 
							} ##############end of outer if ########################
							else
							{
						?>
                                            <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
                                              <tr align="center">
                                                <td width="100%" class="errTxt"> No Payment Types Found </td>
                                              </tr>
                                            </table>
                                            <?
							}   ##################else ends##########################
						?>
                                          </td>
                                        </tr>
                                        <tr>
                                          <td><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                                              <tr>
                                                <td align="center"><input name="Submit" type="submit" class="button" value="Update Sort Order">
                                                </td>
                                              </tr>
                                            </table></td>
                                        </tr>
                                      </table></td>
                                  </tr>
                                  <tr>
                                    <!-- Paging td starts here   -->
                                    <td class="pagingtxt" align="right"><br>
                                      <?
						#################### paging starts ##################
						$page_text=display_paging($totalNoOfRecords,$paging,$pageno);
						echo $page_text;

						#################### paging Ends ##################
						?>
                                      <!--  paging table ends  -->
                                      <script>
							function page_list(pg)
							{
								document.frm2.pageno.value=pg;
								document.frm2.action="<?=$page;?>";
								document.frm2.submit();
							}
							</script>
                                    </td>
                                    <!-- Paging td ends here   -->
                                  </tr>
                                </table></td>
                            </tr>
                          </table></td>
                      </tr>
                    </table>
                  </form></td>
                                  </tr>
                                </table>
                              <table border="0" cellspacing="0" cellpadding="0" align="center" >
                                  <tr>
                                    <td></td>
                                  </tr>
                              </table></td>
                          </tr>
                        </table>
						
						<table cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td><img src="images/1_q4.gif" border="0" alt="" width="10" height="10"></td>
								<td style="width:100%; background-image:url(images/1_li1.gif)"></td>
								<td><img src="images/1_q3.gif" border="0" alt="" width="10" height="10"></td>
							</tr>
						</table>
						


		
		
		</td>

    <td class="col_right">

<table border="0"cellspacing="0" cellpadding="0" class="box_width_right">
	<tr><td></td>
		<td width="100%">
			<table border="0" cellspacing="0" cellpadding="0">
				<tr><td></td></tr>
			</table>
		</td>
	</tr>
</table>


    </td>
  </tr>
</table>



		</td>
	</tr>
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" border="0" style="height:98px; background-image:url(images/bot.gif)">
				<tr>
					<td>
						<table cellpadding="0" cellspacing="0" border="0" class="footer">
							<tr>									
								<td height="77"><img src="images/spacer.gif" border="0" alt="" width="25" height="1"></td>				
								<td style="width:207px"><br style="line-height:49px"><img src="images/p1.gif" border="0" alt="" width="145" height="24"><br></td>
							  <td style="width:532px">&nbsp;</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table></td></tr></table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"></td>
  </tr>
</table>
</body>

</html>